// 获取应用实例
let flag = 0
Page({
  data: {
    swiperImages: {},
    indexImages: [],
    value: ''
  },
  onLoad() {
    flag = 0
    this.getSwiperImages()
    this.getIndexImage()
    wx.showLoading({
      title: '加载中',
    })
    // 定期检查flag的值
    var intervalId = setInterval(function () {
      if (flag === 2) {
        console.log('flag值更改为2')
        wx.hideLoading()
        // 在需要时关闭定时器
        clearInterval(intervalId)
      }
    }, 1000)


  },
  getSwiperImages() {
    //获取轮播图
    const db = wx.cloud.database()
    db.collection('swiper').get().then(res => {
      this.setData({
        swiperImages: res.data
      })
      flag++
    })
  },
  getIndexImage() {
    //获取首页展示图
    const db = wx.cloud.database()
    db.collection('index_show').get().then(res => {
      this.setData({
        indexImages: res.data
      })
      flag++
    })
  },
  //搜索框确认
  onChange(e) {
    this.setData({
      value: e.detail,
    });
  },
  onSearch() {
    this.toSearch()
  },
  onClick() {
    this.toSearch()
  },
  toSearch() {
    wx.navigateTo({
      url: '/pages/index/search/search',
    })
  },
  onShareAppMessage({
    from,
    target
  }) {
    console.log(from, target);
    let myObj = {
      title: `来自${from}的转发,AITO邀您试驾`,
      path: "/pages/home/home",
      imageUrl: "/static/images/car.jpg"
    }
    return myObj;
  },
  onShareAppMessage(res) {
    let myObj = {
      title: '琪琪的手工饰品屋',
      path: "/pages/index/index",
    }
    return myObj;
  }
})